<?php
	include('adodb/adodb.inc.php');
	$user = "admin";
	$pwd = "money";	
	$db = "MoneyManager";
	$server = "localhost";
	
    $DB = NewADOConnection('mysql');
    $DB->Connect($server, $user, $pwd, $db);
   
    global $DB;
    $year = date('Y');
    $month = date('m');
    $dayofmonth =date('d'); // returns today's date
    $dayofweek = date('N'); // returns the day of week sunday etc.
    $year = 2007;
    $month = 12;
    $dayofmonth = 12;
   $dayofweek = 3; */
   
    echo "<br/>";
    if( ($dayofmonth >= 1) and ($dayofmonth <= 6))
    {
       
          if ($dayofmonth == 1)
           {
           // setting up month and year
                if ($month == 1)
                 {
                    $year = $year - 1;
                    $month = 12;
                 }
                else
                 {
                $month = $month - 1;
                 }
          // setting up month and year                              
          
              if($month == 2)
               {
          //  check if year is leap
              if( ($year % 4 == 0 && ($year % 400 == 0 || $year % 100 != 0) == true))
                $dayofmonth = 29;
              else
                 $dayofmonth = 28;   
               }
    
             if(($month==1) || ($month==3) || ($month==5) || ($month==7) || ($month==8) || ($month==10) ||  ($month==12) )
                $dayofmonth = 31;
             else
                if($month !=2)
                {
                $dayofmonth = 30;
                }
           }    

      $dayofmonth = $dayofmonth + 1 - $dayofweek;
      $sunday = $year."-".$month."-".$dayofmonth;     
    }
    else
    {
    $dayofmonth = $dayofmonth - $dayofweek;
    $sunday = $year."-".$month."-".$dayofmonth;     
    }
?>
